package org.jivesoftware.smackx;

import java.util.Iterator;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.XHTMLExtension;

public class XHTMLManager
{
  private static final String namespace = "http://jabber.org/protocol/xhtml-im";

  static
  {
    Connection.addConnectionCreationListener(new ConnectionCreationListener()
    {
      public void connectionCreated()
      {
        XHTMLManager.setServiceEnabled(paramConnection, true);
      }
    });
  }

  public static void addBody(Message paramMessage, String paramString)
  {
    XHTMLExtension localXHTMLExtension = (XHTMLExtension)paramMessage.getExtension("html", "http://jabber.org/protocol/xhtml-im");
    if (localXHTMLExtension == null)
    {
      localXHTMLExtension = new XHTMLExtension();
      paramMessage.addExtension(localXHTMLExtension);
    }
    localXHTMLExtension.addBody(paramString);
  }

  public static Iterator getBodies(Message paramMessage)
  {
    Iterator localIterator;
    XHTMLExtension localXHTMLExtension = (XHTMLExtension)paramMessage.getExtension("html", "http://jabber.org/protocol/xhtml-im");
    if (localXHTMLExtension != null)
      localIterator = localXHTMLExtension.getBodies();
    while (true)
    {
      return localIterator;
      localIterator = null;
    }
  }

  public static boolean isServiceEnabled(Connection paramConnection)
  {
    return ServiceDiscoveryManager.getInstanceFor(paramConnection).includesFeature("http://jabber.org/protocol/xhtml-im");
  }

  public static boolean isServiceEnabled(Connection paramConnection, String paramString)
  {
    boolean bool1;
    boolean bool2;
    try
    {
      bool2 = ServiceDiscoveryManager.getInstanceFor(paramConnection).discoverInfo(paramString).containsFeature("http://jabber.org/protocol/xhtml-im");
      bool1 = bool2;
      return bool1;
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
      bool1 = false;
    }
  }

  public static boolean isXHTMLMessage(Message paramMessage)
  {
    int i;
    if (paramMessage.getExtension("html", "http://jabber.org/protocol/xhtml-im") != null)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  /**
   * @deprecated
   */
  public static void setServiceEnabled(Connection paramConnection, boolean paramBoolean)
  {
    monitorenter;
    try
    {
      boolean bool = isServiceEnabled(paramConnection);
      if (bool == paramBoolean);
    }
    finally
    {
      while (true)
      {
        monitorexit;
        throw localObject;
        ServiceDiscoveryManager.getInstanceFor(paramConnection).removeFeature("http://jabber.org/protocol/xhtml-im");
      }
    }
  }
}